<?php
require 'common.php';
require 'mysql.php';
  
$game_db = new DBPDO($db_config);

$sql = 'select head from user limit 0,1';
$rs = $game_db->select($sql);  

print_r($rs);
$url = '';
$head_url = '';

if ($rs[0]['head']) {
	$head_url = $rs[0]['head'];
}


if ($head_url) {
	$date = date('m-d');
    $file = '/skynet/shao/php/url/'.$date;
    if (!file_exists( $file)){
            mkdir ( $file);
    } 
    $url = 'http://ws.91laoyou.com/head/url/'.$date;
    $file_name = md5($head_url);
    if( !file_exists( $file.'/'.$file_name )){ 

function getCircleAvatar($avatar, $circleAvatar, $r) {
    /**
     * @des     画一个正方形
     * @size    两个半径
     */
    $size = 2 * $r;
    $circle = new Imagick();
    $circle->newImage($size, $size, 'none');
    $circle->setimageformat('png');
    $circle->setimagematte(true);

    /**
     * @des     在矩形上画一个白色圆
     */
    $draw = new ImagickDraw();
    $draw->setfillcolor('#fff');
    $draw->circle($r, $r, $r, $size);
    $circle->drawimage($draw);

    /**
     * @des     裁剪头像成圆形
     */
    $imagick = new Imagick();
    $imagick->readImage($avatar);
    $imagick->setImageFormat('png');
    $imagick->setimagematte(true);
    $imagick->cropimage($size, $size, 30, 0); // 修改裁剪属性
    $imagick->compositeimage($circle, Imagick::COMPOSITE_COPYOPACITY , 0, 0);
    $imagick->writeImage($circleAvatar);
    $imagick->destroy();
}
			$avatar = trim($head_url);
			$circleAvatar = $file.'/'.$file_name;
			$r = 100;
 
			getCircleAvatar($avatar, $circleAvatar, $r);
 
    }
    echo $url.$file_name; 
} 